# Chase Miller
# (heavily modeled off of makefile provided by Kurt Schmidt)
# assignment 1
#

cc=gcc
lex=flex
yacc=bison
pager=less
JAVAC = javac
JAVA = java
CLASSPATH = ./:./java_cup/:./java_cup/java_cup/runtime:./java_cup/java_cup:./JLex

all : view-rdp run-rdp view-gen1 run-gen1 view-gen2 run-gen2 clean
.PHONY : all

### part 1 ####

# recursiveDecentParser.py - takes sample.input

view-rdp : recursiveDecentParser.py
	-$(pager) recursiveDecentParser.py

run-rdp : recursiveDecentParser.py
	chmod +x recursiveDecentParser.py
	python ./recursiveDecentParser.py

### part 2.1 ####

view-gen1 : readListGrammar.py readListLex.py
	-$(pager) readListLex.py
	-$(pager) readListGrammar.py

run-gen1 : readListLex.py readListGrammar.py
	chmod +x readListGrammar.py
	chmod +x readListLex.py
	python readListGrammar.py

### part 2.1 ####

# A java program

view-gen2 :
	-$(pager) readList.lex
	-$(pager) readList.cup
	
run-gen2 : gen2-compile-requirements gen2-lex gen2-parse gen2-compile gen2-run

gen2-parse:
	$(JAVA) -classpath $(CLASSPATH) java_cup.Main readList.cup

gen2-lex:
	$(JAVA) -classpath $(CLASSPATH) JLex.Main readList.lex
	mv readList.lex.java Yylex.java

gen2-compile-requirements:
	@echo CLASSPATH := ${CLASSPATH}
	$(JAVAC) java_cup/java_cup/*.java java_cup/java_cup/runtime/*.java
	$(JAVAC) JLex/*.java
	$(JAVAC) ./*.java	

gen2-compile:
	$(JAVAC) -classpath $(CLASSPATH) sym.java parser.java Yylex.java 
	
gen2-run:
	$(JAVA) -classpath $(CLASSPATH) parser

clean :
	-\rm *.pyc
	-\rm parser.out
	-\rm parsetab.py
	-\rm *.class
	-\rm java_cup/java_cup/*.class java_cup/java_cup/runtime/*.class
	-\rm JLex/*.class
	-\rm Yylex.java
	-\rm parser.java
	-\rm sym.java
	-\rm src/edu/drexel/cs/cs550/*.class
	#-\rm lex.yy.c
	#-\rm list.tab.?
	#-\rm list
